﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UCLibrary.UC
{
    [DefaultEvent("Click")]
    public partial class UCLamp : UserControl
    {
        public UCLamp()
        {
            InitializeComponent();
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }
        private Color _onColor = Color.Green;
        private Color _offColor = Color.Gray;
        public Color onColor
        {
            get { return _onColor; }
            set { _onColor = value; Refresh(); }
        }
        public Color offColor
        {
            get { return _offColor; }
            set { _offColor = value; Refresh(); }
        }
        private string _onText = "1";
        private string _offText = "0";
        public string onText
        {
            get { return _onText; }
            set { _onText = value; Refresh(); }
        }
        public string offText
        {
            get { return _offText; }
            set { _offText = value; Refresh(); }
        }
        private bool _isON = false;
        [Category(""), Description("值为真灯亮")]
        public bool isON
        {
            get { return _isON; }
            set { _isON = value; Refresh(); }
        }
        private Font _font = new Font("微软雅黑",20f,FontStyle.Bold);
        public Font font
        {
            get { return _font; }
            set { _font = value; Refresh(); }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            Function.setHighQuality( g);
            GraphicsPath path = new GraphicsPath();
            path.AddEllipse(new RectangleF(0,0,Width,Height));
            Region = new Region(path);
            StringFormat stringFormat = new StringFormat();
            stringFormat.Alignment = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;

            if (isON)
            {
                g.FillPath(new SolidBrush(onColor), path);
                g.DrawString(onText, font, Brushes.White, new RectangleF(0, 0, Width, Height), stringFormat);
            }
            else
            {
                g.FillPath(new SolidBrush(offColor), path);
                g.DrawString(offText, font, Brushes.White, new RectangleF(0, 0, Width, Height), stringFormat);
            }
        }

    }
}
